package com.yb.java.singleton;

/**
 * @program: design-pattern
 * @description: 双重检测单例模式。这种模式安全且在多线程情况下保持高性能。
 * @author: Mr.Bo
 * @create: 2021-04-25 20:47
 **/
public class DoubleTestSingleton {

    private volatile static DoubleTestSingleton instance;

    private DoubleTestSingleton(){}

    public static DoubleTestSingleton getInstance(){
        if (instance == null){
            synchronized (DoubleTestSingleton.class){
                if (instance == null){
                    instance = new DoubleTestSingleton();
                }
            }
        }
        return instance;
    }
}
